/**
 * Created by Mr.Xing on 2018/10/16.
 */
mini.parse();
mini_debugger = false;
// grid.load(ajaxUrl + "/tableClass/list.do");
var url = bootPATH + "../frame/frame1/pages/formLayout";

var grid = mini.get("tableClass");//主表
var grid_child = mini.get("tableClass_child");//子表

var ids = [];
var type;//主子表(main/child)
var mode;//布局方式
var properties = [];//存放数据
var cRefObj = [];//存放属性

var click_type;
var click_types = [];
var click_ids = [];
var action;
var edit_data;
var formListId;
var formName;
var menuJump = parent.isMenuJump();//是否是菜单跳转（add）
if(menuJump) {
    action = 'add';
    edit_data = [];
    formListId = '';
    formName = '';

}else {//按钮跳转

    var formDesignAction = localStorage.getItem("formDesignAction");
    console.log(formDesignAction);
    console.log($.parseJSON(formDesignAction));
    formDesignAction = $.parseJSON(formDesignAction)[0];
    console.log(formDesignAction,'formDesignAction');

    action = formDesignAction.action;//add/edit
    edit_data = formDesignAction.edit_data;//编辑的数据
    formListId = formDesignAction.formListId;
    formName = formDesignAction.formName;
}



var mainTreeData;
$.ajax({
    url: ajaxUrl + "/tableClass/list.do",
    type: "POST",
    success: function (data) {
        mainTreeData = dbTree(grid,data.data);//获取主表树
        //编辑模式，进入页面时：选中树，生成组件
        if(action == 'edit' ) {
            // var edit_id = form_edit_id;//form_edit_id为index.js全局变量
            mini.get("fname").setValue(edit_data[0].formList.formName);
            setMainCheckedNodes(edit_data);//设置选中树
            $.ajax({
                url: ajaxUrl + "/tableClass/findAll.do",
                type: "POST",
                success: function (data) {
                    data = data.data;
                    var findAllData = [];
                    // console.log(data,'所有数据（主表+子表）');
                    for(var i=0;i<data.length;i++) {
                        findAllData[i] = {
                            tableClassName: data[i].tableClassName,
                            tableChClassName: data[i].tableChClassName,
                            cTableName: data[i].tableChClassName,
                            field: '',
                            fieldCh: '',
                            tableClassId: data[i].tableClassId + '',//id
                            PID: -1,
                            mTableId: data[i].mTableId,//0为主表
                            checked: false,
                            expanded: true,
                            children:[]
                        };
                        for(var j=0;j<data[i].createTables.length;j++) {
                            var c = data[i].createTables[j];
                            findAllData[i].children.push({
                                // cTableField: c.field,
                                cTableName: data[i].tableChClassName,
                                tableClassName: data[i].tableClassName,
                                type: c.type,
                                field: c.field,
                                fieldCh: c.fieldCh,
                                tableClassId: c.tableId + '',//id
                                PID: data[i].tableClassId + '',
                                mTableId: data[i].mTableId,//0为主表
                                expanded: true,
                                checked: false
                            });
                        }
                    }
                    // console.log(findAllData,'findAllData');
                    var nodes = [];
                    for(var i=0;i<findAllData.length;i++){
                        var children = findAllData[i].children;
                        for(var j=0;j<children.length;j++){
                            nodes.push(children[j]);
                        }
                    }
                    // console.log(nodes,'nodes');//所有的主子表的节点数组
                    var arrs = [];
                    for(var p=0;p<edit_data.length;p++) {
                        for(var j=0;j<nodes.length;j++) {
                            if (edit_data[p].checkboxId == nodes[j].tableClassId) {
                                var arr = [];//存放被选中的节点
                                nodes[j].checked = true;
                                nodes[j].iConX = edit_data[p].iConX;
                                nodes[j].iConY = edit_data[p].iConY;
                                nodes[j].iLabHeight = edit_data[p].iLabHeight;
                                nodes[j].iWidth = edit_data[p].iWidth;
                                nodes[j].iLabWidth = edit_data[p].iLabWidth;
                                nodes[j].cEditCss = edit_data[p].cEditCss;
                                nodes[j].cRefObj = edit_data[p].cRefObj;
                                nodes[j].formList = edit_data[p].formList;//表单id，名称

                                arr.node = nodes[j];
                                arr.isLeaf = true;
                                if(nodes[j].mTableId == 0) {
                                    type = 'main'
                                }else {
                                    type = 'child'
                                }
                                // console.log(arr,'----');
                                arrs.push(arr);
                                onNodeCheck(arr,true);

                            }
                        }
                    }
                    console.log(arrs,'arrs');

                    //主表禁用
                    for(var x=0;x<arrs.length;x++) {
                        if(arrs[x].node.mTableId == 0) {
                            for(var y=0;y<dbData.length;y++) {
                                if (dbData[y].tableClassName != arrs[x].node.tableClassName) {
                                    var ch = dbData[y].children;
                                    for (var z = 0; z < ch.length; z++) {
                                        grid.disableNode(ch[z].tableClassId);//禁用其他表字段
                                    }
                                }
                            }
                        }
                    }
                },
                error : function(data){
                }
        });
        }
    },
    error : function(data){
    }
});


//表格树数据加载
var dbData = [];//存放转换后的数据库表数据
function dbTree(grid,data) {
    dbData = [];
    console.log(data,'data');
    for(var i=0;i<data.length;i++) {
        dbData[i] = {
            tableClassName: data[i].tableClassName,
            tableChClassName: data[i].tableChClassName,
            cTableName: data[i].tableChClassName,
            field: '',
            fieldCh: '',
            tableClassId: data[i].tableClassId + '',//id
            PID: -1,
            checked: false,
            expanded: true,
            children:[]
        };
        for(var j=0;j<data[i].createTables.length;j++) {
            var c = data[i].createTables[j];
            dbData[i].children.push({
                // cTableField: c.field,
                cTableName: data[i].tableChClassName,
                tableClassName: data[i].tableClassName,
                // formListId: data[i].formListId,
                type: c.type,
                field: c.field,
                fieldCh: c.fieldCh,
                tableClassId: c.tableId + '',//id
                PID: data[i].tableClassId + '',
                expanded: true,
                checked: false
            });
        }
    }
    console.log(dbData,'dbData');
    grid.setData(dbData);
    return dbData;
}

//禁用其他主表（表头唯一）
function unique(e) {
    if(e.node.checked) {//若为选中
        for(var i=0;i<mainTreeData.length;i++) {
            if(mainTreeData[i].tableClassName != e.node.tableClassName) {
                var c = mainTreeData[i].children;
                for(var j=0;j<c.length;j++) {
                    grid.disableNode(c[j].tableClassId);//禁用其他表字段
                }
            }
        }
    }else {//若为取消选中
        //判断所属表中是否还有被选中的，若无则取消禁用
        var flag = true;
        for(var i=0;i<mainTreeData.length;i++) {
            if(mainTreeData[i].tableClassName == e.node.tableClassName) {//被选中的节点所属表
                var c = mainTreeData[i].children;
                for(var j=0;j<c.length;j++) {
                    if(c[j].checked) {
                        flag = false;//不能启用
                    }
                }
            }
        }
        if(flag) {
            for(var i=0;i<mainTreeData.length;i++) {
                var c = mainTreeData[i].children;
                for(var j=0;j<c.length;j++) {
                    grid.enableNode(c[j].tableClassId);
                }
            }
        }
    }
}

//主子表复选框选中事件
grid.on("nodecheck",function (e) {
    type = 'main';
    unique(e);
    onNodeCheck(e);
});
grid_child.on("nodecheck",function (e) {
    type = 'child';
    onNodeCheck(e);
});

//复选框点击事件
function onNodeCheck(e,setPosition) {
    // console.log(e.sender);//树对象
    var node = e.node;//点击的node对象
    var isLeaf = e.isLeaf;//是否是子节点
    console.log(node,'点击的node');
    console.log(isLeaf,'子节点');
    console.log(ids,'ids');
    mode = getLayoutMode();

    if(isLeaf) {//子节点

        if(node.checked == true) {//添加单个组件

            if($.inArray(node.field, ids) == -1) {//组件不存在
                //增加单个组件
                var fListId;
                var fName;
                if(action == 'edit') {
                    fListId = formListId;//表单id
                    fName = formName;//表单名称
                }else if(action == 'add') {
                    fListId = '';
                    fName = '';
                }
                if(type == 'main') {//主表，生成组件
                    createForm(node);
                    ids.push(node.field);//已创建的组件id数组
                    console.log(ids,'push ids');
                    properties.push({
                        cLadText: node.fieldCh,//字段中文名
                        cTableField:node.field,//字段英文名(唯一)
                        // cRefObj: {},
                        cRefObj: node.cRefObj,
                        cTableName:node.tableClassName,//数据库表名(英文)
                        tableClassName:node.tableName,//数据库表名(中文)
                        checkboxId:node.tableClassId,//复选框id
                        iConX: node.iConX,
                        iConY: node.iConY,
                        iLabHeight: node.iLabHeight,
                        iWidth: node.iWidth,
                        iLabWidth: node.iLabWidth,
                        cEditCss: node.cEditCss,
                        formList:{
                            formListId: fListId,//编辑的表单id
                            formName: fName
                        },
                        type: 'main'
                    });
                    console.log(properties,'增加单个组件');

                }else if(type == 'child') {//子表，生成表格
                    createTable(node);
                    ids.push(node.field);//已创建的组件id数组
                    console.log(ids,'push ids');
                    properties.push({
                        cLadText: node.fieldCh,//字段中文名
                        cTableField:node.field,//字段英文名(唯一)
                        // cRefObj: {},
                        cRefObj: node.cRefObj,
                        cTableName:node.tableClassName,//数据库表名(英文)
                        tableClassName:node.tableName,//数据库表名(中文)
                        checkboxId:node.tableClassId,//复选框id
                        iConX: node.iConX,
                        iConY: node.iConY,
                        iLabHeight: node.iLabHeight,
                        iWidth: node.iWidth,
                        iLabWidth: node.iLabWidth,
                        cEditCss: node.cEditCss,
                        formList:{
                            formListId: fListId,//编辑的表单id
                            formName: fName
                        },
                        type: 'child'
                    });
                    console.log(properties,'增加表格列');
                }
                console.log(properties,'properties');
                var p =properties[properties.length-1];
                console.log(p,'p');

                if(setPosition) {//编辑模式，需要设置组件位置
                    if(p.type == 'main') {//组件
                        $('#'+ p.cTableField).css({
                            clear: 'both',
                            left: p.iConX,
                            top: p.iConY,
                            width: p.iWidth,
                            height: p.iLabHeight
                        })
                        // $('#lab'+ p.cTableField).css({
                        //     width: p.iWidth - p.iLabWidth,
                        //     height: p.iLabHeight
                        // });
                        $('#k'+ p.cTableField).css({
                            width: p.iLabWidth,
                            // height: p.iLabHeight
                        });

                    }else if(p.type == 'child') {//表格
                        $('#'+ p.tableClassName).css({
                            width: p.iWidth,
                            height: p.iLabHeight,
                            left: p.iConX,
                            top: p.iConY,
                            clear: 'both'
                        })
                    }
                }
            }else {
                mini.alert('组件已存在！');
            }

        }else if(node.checked == false) { //删除单个组件

            for(var i=0;i<properties.length;i++) {
                if(properties[i].cTableField == node.field) {
                    if(properties[i].type == 'main') {//移除表单
                        $('#'+ node.field).remove();
                    }else if(properties[i].type == 'child') {//移除表格
                        delTable(node);
                    }
                    //移除数据
                    properties.splice(i, 1);
                    ids.splice( ids.indexOf(node.field), 1 );
                }
            }
            console.log(properties,'已删除',node.field);
            console.log(ids,'pop ids');
        }

    }else {//父节点

    }

}

// 创建组件
function createForm(node) {
    var id = node.field;//+ node.tableClassName
    $("#formTable").append("<div class='fuzhu' id='"+ id + "' title='" + id + "'>" +
        "  <li style='width: 95px;float: left;height: 100%;background: #ccc;overflow: hidden;text-align: center;line-height: 40px;' id='li" + id + "'>" + node.fieldCh + "</li>" +
        "  <label class='lab1' id='lab" + id + "'></label>" +
        "  <input id='k" + id + "' type='text' mytype='text' style='left:98px;height:100%;position: absolute;width:100px;'>" +
        "</div>");
    $item = $("#" + id);
    $item.resizable({
        handles: 'n, e, s, w, ne, se, sw, nw',
        grid: [2, 2],
        resize: function () {
            $('#li' + $(this).attr('id')).css('line-height', $('#li' + $(this).attr('id')).height() + 'px');
            console.log($(this).width() - $('#li' + $(this).attr('id')).width() - 3 + 'px');
            $('#k' + $(this).attr('id')).css('width', $(this).width() - $('#li' + $(this).attr('id')).width() - 3 + 'px')
        }
    });
    var clickX, leftOffset;
    var dragging = false;
    var labBtn = $('#lab' + id);
    //按下鼠标
    labBtn.bind('mousedown', function (e) {
            dragging = true;
            // console.log($(this).attr('id'));
            leftOffset = $('#' + $(this).attr('id').substring(3)).offset().left;//左坐标
            $('#' + $(this).attr('id').substring(3)).draggable('disable');
            //按下并拖动鼠标
            $('#' + $(this).attr('id').substring(3)).bind('mousemove', function (e) {
                clickX = e.pageX;
                console.log(e.pageX);
                $('#li' + $(this).attr('id')).css('width', clickX - 7 - leftOffset + 'px');
                $('#lab' + $(this).attr('id')).css('left', clickX - 7 - leftOffset + 'px');
                $('#k' + $(this).attr('id')).css('left', clickX - 4 - leftOffset + 'px');
                $('#k' + $(this).attr('id')).css('width', $(this).width() - clickX + 4 + leftOffset + 'px');
            })
            e.stopPropagation();
    });

    $item.mouseup(function (e) {
        $('#' + $(this).attr('id')).unbind('mousemove');
        $('#' + $(this).attr('id')).draggable('enable');
        dragging = false;
    })
    // $item.css("position", "absolute");
    $item.draggable({
        grid: [2, 2],
        containment: "parent",
        snap: true,
        snapTolerance: 20,
        start: function () {

        },
        stop: function () {

        }
    });

    // $item.click(fuzhuclick);//点击事件
    $item.mouseup(fuzhuclick);//点击事件(鼠标松开时发生)
}

// 创建表格
function createTable(node) {
    var id = node.field;
    var table = mini.get(node.tableClassName);

    if(table)  {//表格存在，只需增加列
        var cols =  table.getColumns();
        console.log(cols,'cols');
        cols.push({
            field: node.field, header: node.fieldCh, width:100, headerAlign: "center", allowSort: false
        })
        table.set({
            columns: cols
        });
        table.setData([{},{}]);

    }else {//表格不存在，创建

        var grid = new mini.DataGrid();//js创建表格
        grid.set({
            url: "",
            style:"",
            id: node.tableClassName,
            columns: [{
                field: node.field, header: node.fieldCh, width:100, headerAlign: "center", allowSort: false
            }],
            multiSelect:false,
            allowResize:true,
            showPager:false,
            allowRowSelect: false,
            allowColumnSelect: true,
            // allowCellSelect: true
        });
        grid.render(document.getElementById("formTable"));
        var data = [{},{}];
        grid.setData(data);
        $( "#" + node.tableClassName ).draggable({
            containment: "#formTable",
            scroll: false,
            cursor: "move"
        });
        grid.on("headercellclick",function (e) {
            // console.log(e.sender,'sender');//表格对象
            console.log(e.column,'cols');//列对象

            click_type = "table";
            click_types.push("table");
            var pre_click_type = click_types.slice(-2, -1).toString();//上一个需要存起来的属性的类型,为空则为第一次点击，不存储
            var thisId = e.column.field;
            click_ids.push(thisId);
            var pre_click_id = click_ids.slice(-2, -1).toString();//上一个需要存起来的属性的id

            savePre(pre_click_type,thisId,pre_click_id);
            tableType();//更新复选框联动
        })
    }

}
// 删除表格
function delTable(node) {
    var id = node.field;
    var table = mini.get(node.tableClassName);
    var cols =  table.getColumns();
    console.log(cols,'cols');
    for(var i=0;i<cols.length;i++) {
        if(cols[i].field == id) {
            cols.splice(i, 1);//移除列
            if(cols.length == 0) {//列不存在，删除表格
                $('#'+ node.tableClassName).remove();
                table.destroy();
                mini.parse();
            }else {
                table.set({
                    columns: cols
                });
                table.setData([{},{}]);
            }
        }
    }
}

//点击组件
function fuzhuclick() {
    click_type = "form";
    click_types.push("form");
    var pre_click_type = click_types.slice(-2, -1).toString();//上一个需要存起来的属性的类型,为空则为第一次点击，不存储
    var thisId = $(this).attr('id');
    click_ids.push(thisId);
    var pre_click_id = click_ids.slice(-2, -1).toString();//上一个需要存起来的属性的id

    savePre(pre_click_type,thisId,pre_click_id);
    tableType();//更新复选框联动
}

//主子表联动
function onSelectionChanged(e) {

    // var grid = e.sender;
    var record = grid.getSelected();
    if (record) {
        console.log(record,'选择的主表');

        $.ajax({
            url: ajaxUrl + "/tableClass/findByMTableToSTable.do",
            type: "POST",
            data: {
                tableClassId: record.tableClassId
            },
            success: function (data) {
                // console.log(data,'data')
                dbTree(grid_child,data.data);
                $('#tableClass_child').css({
                    height: $('#form-outlookbar').height() - $('#tableClass').height()
                })

                var checkedNodes = [];
                for(var i=0;i<dbData.length;i++) {
                    var c = dbData[i].children;
                    for(var j=0;j<c.length;j++) {
                        for(var k=0;k<properties.length;k++) {
                            if(c[j].tableClassId == properties[k].checkboxId) {
                                // console.log(c[j].tableClassId,'需要勾选的');
                                checkedNodes.push(c[j].tableClassId);
                            }
                        }
                    }
                }
                grid_child.setValue(checkedNodes.join(','));
                // if(action == 'edit') {
                // checkedNodes = [];
                // for(var i=0;i<edit_data.length;i++) {
                //     for (var j = 0; j < properties.length; j++) {
                //         if(edit_data[i].checkboxId == properties[j].checkboxId) {
                //             checkedNodes.push(edit_data[i].checkboxId);
                //         }
                //     }
                // }
                // setChildCheckedNodes(checkedNodes);
                // }
            },
            error : function(data){
            }
        });
    }
}

//编辑模式，进入页面选中节点
var checkedNodes;
function setMainCheckedNodes(edit_data) {
    checkedNodes = [];
    for(var i=0;i<edit_data.length;i++) {
        checkedNodes.push(edit_data[i].checkboxId);
    }
    grid.setValue(checkedNodes.join(','));
}
function setChildCheckedNodes(edit_data) {
    // checkedNodes = [];
    // for(var i=0;i<edit_data.length;i++) {
    //     checkedNodes.push(edit_data[i].checkboxId);
    // }
    grid_child.setValue(checkedNodes.join(','));
}

function getCheckedNodes() {
    var checked = grid.getCheckedNodes();
    console.log(checked,'checked');
}

var id_now;
function savePre(pre_type,id,pre_id) {
    console.log(pre_type,'需存储的上一个的类型');
    console.log(pre_id,'需存储的上一个的id');
    console.log('点击了',click_type);
    id_now = id;
    console.log('当前id',id_now);
    console.log('properties',properties);
    //存储
    for(var i=0;i<properties.length;i++) {
        if(properties[i].cTableField == pre_id) {
            properties[i].cRefObj = mini.decode(getForm());
        }
    }
    console.log('已存储pre',properties);
    //更新属性
    for(var i=0;i<properties.length;i++){
        if(id_now == properties[i].cTableField) {
            var cRef = properties[i].cRefObj;
            console.log(cRef,'需要显示的属性');
            resetForm();
            if(typeof cRef == 'string') {
                cRef = $.parseJSON(cRef)
            }
            setForm(cRef);
        }
    }

}

function save() {
    savePre(click_type,id_now,id_now);//保存最后的数据
    //处理数据
    var formTable = $("#formTable").children();
    console.log(formTable,'formTable');
    for(var i = 0; i < formTable.length; i++){
        for(var j=0;j<properties.length;j++) {
            if(properties[j].type == 'main') {

                var p_id = properties[j].cTableField;
                if(formTable[i].id == p_id) {
                    properties[j].iConX = formTable[i].offsetLeft;
                    properties[j].iConY = formTable[i].offsetTop;
                    properties[j].cEditCss = formTable[i].className;
                    properties[j].iLabHeight = formTable[i].offsetHeight;
                    properties[j].iWidth = formTable[i].offsetWidth;
                    properties[j].iLabWidth = formTable[i].children[2].offsetWidth;
                }
            }else if(properties[i].type == 'child') {

                var p_id = properties[i].cTableName;
                if(formTable[i].id == p_id) {
                    properties[j].iConX = formTable[i].offsetLeft;
                    properties[j].iConY = formTable[i].offsetTop;
                    properties[j].cEditCss = formTable[i].className;
                    properties[j].iLabHeight = formTable[i].offsetHeight;
                    properties[j].iWidth = formTable[i].offsetWidth;
                    properties[j].iLabWidth = formTable[i].offsetWidth;
                }
            }
        }
    }
    for(var i = 0; i < properties.length; i++) {
        properties[i].cRefObj.id = properties[i].cTableField;
        properties[i].lanyoutMent = mode;
        // properties[i].cRefObj.cType = switchRef(properties[i].cRefObj.cType);
        properties[i].cType = properties[i].cRefObj.cType;
        properties[i].parId = modularId;
        properties[i].modularId= parId;
        properties[i].cFormName = mini.get("fname").getValue();
        properties[i].formList.formName = mini.get("fname").getValue();
    }
    console.log(properties,'数据');

    formValid();//表单验证
    if(!parId) {//菜单是否选中验证
        mini.alert('请选择菜单');
        return;
    }

    //传数据
    var data = JSON.stringify(properties);
    // console.log(data);
    var url;
    // save_flag++;
    // if(save_flag > 0) {//编辑
    //     action == 'edit';
    // }
    if(action == 'edit') {
        url =  ajaxUrl + "/formltems/updateForm.do";
    }else {
        url =  ajaxUrl + "/formltems/insertForm.do";
    }

    $.ajax({
        type : 'POST',
        url : url,
        dataType : 'json',
        contentType: "application/json",
        data : data,
        success: function (data) {
            mini.alert('保存成功！');
            // parent.removeTab();//保存成功，关闭页面
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert('保存失败！');
            // console.log(jqXHR);
        }
    })

}

//选择所属菜单
var modularId;
var parId;
function setMenu() {
    mini.open({
        url : bootPATH + "../frame/frame1/pages/formLayout/formDesign_selectMenu.html",
        title : "选择所属菜单",
        onload: function () {       //弹出页面加载完成
            // var iframe = this.getIFrameEl();
            // var data = { action: "edit-db", id: id, properties: properties };
            // iframe.contentWindow.SetDbData(data);
        },
        ondestroy: function (action) {  //弹出页面关闭前
            if (action == "ok") {       //如果点击“确定”
                var iframe = this.getIFrameEl();
                var data = iframe.contentWindow.onTableOk();
                data = mini.clone(data);
                console.log(data,'----');
                // modularId = data[0].id.slice(6);//节点id
                // parId = data[0].pid.slice(6);//父节点id
                modularId = data[0].id.replace(/[^0-9]/ig,"");//节点id
                parId = data[0].pid.replace(/[^0-9]/ig,"");//父节点id
                console.log(modularId,'modularId');
                console.log(parId,'parId');
            }
        }
    })
}

//获取布局方式
function getLayoutMode() {
    var layoutMode = mini.get("layoutMode").getValue();
    var Mode;
    if(layoutMode == '自由布局') {
        Mode = '1';
    }else if(layoutMode == '表格布局') {
        Mode = '2';
    }
    console.log(Mode,'布局方式');
    return Mode;
}

//表单验证
function formValid() {
    var form1 = new mini.Form("#fname");
    var form2 = new mini.Form("#dataType");
    var form3 = new mini.Form("#typeId");
    form1.validate();
    form2.validate();
    form3.validate();
    if (form1.isValid() == false) {
        alert('表单名称不能为空');
        return;
    }
    if (form2.isValid() == false) {
        alert('请选择参照类型');
        return;
    }
    if (form3.isValid() == false) {
        alert('请选择数据来源');
        return;
    }
}

//表单操作
function getForm() {
    var form = new mini.Form("#form1");
    var data = form.getData();
    var s = mini.encode(data);
    return s;
}
function setForm(obj) {
    var form = new mini.Form("#form1");
    // if(obj) {
    //     obj.cType = switchRef(obj.cType);
    // }
    form.setData(obj, false);
}
function resetForm() {
    var form = new mini.Form("#form1");
    form.reset();
}
function clearForm() {
    var form = new mini.Form("#form1");
    form.clear();
}



//左对齐
function leftAlignment() {
    var formTable = $("#formTable").children();
    console.log(formTable,'formTable');
    for(var i = 0; i < formTable.length; i++){
        // console.log($("#"+ formTable[i].title));
        $("#"+ formTable[i].id).css({ "left": "0px", "float": "none"});
    }
}
//右对齐
function rightAlignment() {
    var formTable = $("#formTable").children();
    for(var i = 0; i < formTable.length; i++){
        $("#"+ formTable[i].id).css({ "left": "auto", "right": "0px", "float": "right"});
    }
}
//上对齐
function alignTopEdge() {
    var formTable = $("#formTable").children();
    for(var i = 0; i < formTable.length; i++){
        $("#"+ formTable[i].id).css({ "top": "0px", "float": "none"});
    }
}
//下对齐
function bottomJustify() {
    var formTable = $("#formTable").children();
    for(var i = 0; i < formTable.length; i++){
        $("#"+ formTable[i].id).css({ "top": "auto", "bottom": "0px", "position": "absolute", "float": "none"});
    }
}
//刷新
function  refresh() {
    // window.location.reload();
}

function switchRef(obj) {
    switch(obj){
        case 'textbox': return '文本';
        case 'textarea': return  '文本域';
        case 'buttonedit': return '参照';
        case 'datepicker': return'日期';
        case 'combobox': return '枚举';
        case 'upload': return '附件';
        case 'checkbox': return '复选框';
        case 'radio': return '单选框';
        case 'yeqian': return '页签';
        case 'table': return '表格';
        case 'treeselect': return '树形';
        case 'treeGrid': return '树形及表格';
    }
}